<template>

    <div v-if="abc.user.id">
        科室名称<input type="text" v-model="querInfo.HospName">
        科室类别<input type="text" v-model="querInfo.HospType">
        <input type="button" value="查询" @click="show">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>序号</td>
                    <td>科室名称</td>
                    <td>科室类别</td>
                    <td>使用状态</td>
                    <td>门诊诊室</td>
                    <td>住院病区</td>
                    <td>科室简介</td>
                    <td>科室电话</td>
                    <td>操作</td>
                </tr>
                <tr v-for="item in data.list">
                    <td>{{ item.hospId }}</td>
                    <td>{{ item.hospName }}</td>
                    <td>{{ item.hospType }}</td>
                    <td>{{ item.hospState }}</td>
                    <td>{{ item.hospRoom }}</td>
                    <td>{{ item.hospArea }}</td>
                    <td>{{ item.hospJj }}</td>
                    <td>{{ item.hospTel }}</td>
                    <td><input type="button" value="删除" @click="del(item.hospId)">
                        <input type="button" value="修改" @click="update(item.hospId)">
                        <input type="button" value="详情">
                    </td>
                </tr>
            </tbody>
        </table>
        <span>共{{ data.totalCount }}条</span>
        <span>共{{ data.totalPgae }}页</span>
        <span>{{ querInfo.Index }}/{{ data.totalPgae }}</span>

        <input type="button" value="首页" @click="total(1)">
        <input type="button" value="上一页" @click="total(querInfo.Index - 1)">
        <span v-for="item in data.totalPgae" @click="total(item)">&nbsp;&nbsp;{{ item }}&nbsp;</span>
        <input type="button" value="下一页" @click="total(querInfo.Index + 1)">
        <input type="button" value="尾页" @click="total(data.totalPgae)">

    </div>
    <div v-else>
        <span>未登录</span>
        <input type="button" value="首页" @click="router.push('/login')">

    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();
import { useStore } from '@/stores/user';
const abc = useStore();

let querInfo: any = reactive({
    Index: 1,
    Size: 2,
    HospName: "",
    HospType: ""
})
let data: any = reactive({
    list: [],
    totalCount: 0,
    totalPgae: 0,

})

onMounted(() => {
    lists();
})

const upd=(id:any)=>{
    router.push({
        
    })
}

const update = (id: any) => {
    router.push({
        path: '/update',
        query: {
            id: id
        }

    })
}


const lists = () => {
    axios({
        url: '/api/Hosp/HospList',
        method: 'get',
        params: {
            Index: querInfo.Index,
            Size: querInfo.Size,
            HospName: querInfo.HospName,
            HospType: querInfo.HospType
        }
    })
        .then((res) => {
            console.log(res)
            Object.assign(data, res.data)
        })
}
const show = () => {
    querInfo.Index = 1;
    lists();
}
const del = (id: any) => {

    if (confirm("是否删除")) {
        axios({
            url: '/api/Hosp/HospDelete',
            method: 'delete',
            params: {
                ids: id
            }
        })
            .then((res) => {
                if (res.data > 0) {
                    alert("删除成功");
                    show();
                }
                else {
                    alert("删除失败");
                    return;
                }
            })
    }
}

const total1 = (num: any) => {
    if (num < 1) {
        querInfo.Index = 1;
        return;
    }
    if (num > data.totalPgae) {
        querInfo.Index = data.totalPgae;
        return;
    }
    querInfo.Index = num;
    lists;
}

const total = (num: any) => {
    if (num < 1) {
        querInfo.Index = 1;
        return;
    }
    if (num > data.totalPgae) {
        querInfo.Index = data.totalPgae;
        return;
    }
    querInfo.Index = num;
    lists;
}


</script>

<style scoped></style>